﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>

    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <style>
        .vue-treeselect__control {
            height: 100%;
            border: none;
            background: none;
        }

        .vue-treeselect__placeholder {
            top: -3px;
        }

        .vue-treeselect__single-value {
            top: -3px;
        }

        .el-input__suffix {
            /* z-index: 9; */
        }
    </style>
</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px" label-height="300px"
                 size="mini" label-position="right">
            <el-row>

                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.name" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{SysMenu.Name+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11" offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.code" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{SysMenu.Code+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

            </el-row>
            <el-row>

                <el-col :span="11">
                    <div class="elst-select-mini">
                        <div class="el-input el-input--mini el-input-group el-input-group--prepend">
                            <div class="el-input-group__prepend">
                                {{SysMenu.SerialNumber+mark.m}}
                            </div>
                            <div>
                                <el-input-number class="el-input__inner" v-model="Form.serialNumber" :min="1"
                                                 label="描述文字" size="mini">
                                </el-input-number>

                            </div>

                        </div>
                    </div>
                    <!-- <div class="elst-select-mini">
                        <el-form-item>
                            <el-input>
                                <template slot="prepend">
                                    <div> {{SysMenu.SerialNumber+mark.m}}</div>
                                </template>
                                <el-input-number slot="suffix" v-model="Form.serialNumber" controls-position="right"
                                    :min="1">
                                </el-input-number>
                            </el-input>
                        </el-form-item>
                    </div> -->
                </el-col>

                <el-col :span="11" offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{SysMenu.ParentId+mark.m}}
                                </template>
                                <treeselect v-model="Form.parentId" :options="MenuList" :flat="true" slot="suffix"
                                            style="line-height: 28px;width:70%;float: right;" placeholder="请选择" />
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.url" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{SysMenu.Url+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

            </el-row>
            <el-row>

                <el-col :span="11">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item>
                                <el-input size="mini">
                                    <template slot="prepend">
                                        <div> {{SysMenu.Type+mark.m}}</div>
                                    </template>
                                    <el-select @visible-change="visibleChange" v-model="Form.type" slot="suffix" :placeholder="SysMenu.type">
                                        <el-option label="请选择" value=""></el-option>
                                        <el-option label="菜单" :value="0"></el-option>
                                        <el-option label="功能" :value="1"></el-option>
                                    </el-select>
                                </el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
            </el-row>

            <el-row>
                <div class="elst-select-mini">
                    <el-form-item>
                        <template>
                            <el-checkbox v-model="Form.isGroup">{{SysMenu.IsGroup}}</el-checkbox>
                            <el-checkbox v-model="Form.isFactory">{{SysMenu.IsFactory}}</el-checkbox>
                            <el-checkbox v-model="Form.isShare">{{SysMenu.IsShare}}</el-checkbox>
                        </template>
                    </el-form-item>
                </div>

            </el-row>

            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{SysMenu.Remarks+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea" v-model="Form.remarks"
                                          autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>

                <!-- <el-col :span="24">
                    <el-form-item :label="SysMenu.Remarks+mark.m" prop="Remarks" class="inputTextarea">
                        <el-input type="textarea" v-model="Form.remarks" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col> -->
            </el-row>


            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSubmit}}</el-button>
                    <!-- <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSubmit}}</el-button> -->
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>

    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        app = new Vue({
            el: '#app',
            data: {
                id: '',//父业传参
                Form: {
                    parentId: null
                },//业务表单内容
                MenuList: [],//下拉树
                Types: [],//类型
                rules: {}//表单验证
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            onSubmitForm(this, '/api/Menu/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });

                },
                getData: function () {
                    getData(this, '/api/Menu/get?id=' + this.id);
                },
                GetPageData: function (currentIndex) {
                    var mythis = this;
                    myAjax("post", this, '/api/Menu/GetList', null, function (response) {
                        var data = MenuHelper(response.data, "");
                        mythis.MenuList = data;
                        //mythis.MenuList.unshift({ id: null, label: '无父级' })//初始化无父级的选项
                    }, false);
                },
            },
            mounted: function () {
                this.GetPageData(1);//绑定下拉树
                this.Types = [];//类型
                this.id = getUrlParam("id");
                var pid = getUrlParam("menuId");
                this.Form.parentId = pid;
                this.getData();
            }
        });

        //数据序列化（下拉树）
        function MenuHelper(list, pid) {
            var result = [];
            list.forEach(function (v, i) {
                if (v.parentId == pid) {
                    var obj = {};
                    for (var key in v) {
                        obj[key] = v[key];
                    }
                    obj.label = v.name;
                    var nextObj = MenuHelper(list, v.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>